using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using QLNS.Data;
using QLNS.Object;
using System.Windows.Forms;

namespace QLNS.Control
{
    class GiamTruCtrl
    {
        GiamTruData data = new GiamTruData();

        BindingSource bs = new BindingSource();
        public void HienthiGiamTruDataGridview(DataGridView dg, BindingNavigator bn)
        {
            BindingSource bs = new BindingSource();
            DataTable tbl = data.DanhSachGiamTru();
            bs.DataSource = tbl;
            bn.BindingSource = bs;
            dg.DataSource = bs;

        }

        public IList<GiamTruInfo> LayDanhSachGiamTru()
        {
            DataTable tbl = data.DanhSachGiamTru();
            IList<GiamTruInfo> ds = new List<GiamTruInfo>();

            foreach (DataRow row in tbl.Rows)
            {
                GiamTruInfo giamtru = new GiamTruInfo();
                giamtru.Thang = Convert.ToDateTime(row["Thang"]);
                giamtru.ID = Convert.ToString(row["ID"]);
                giamtru.Ten = Convert.ToString(row["Ten"]);
                giamtru.BaoHiemXaHoi = Convert.ToDouble(row["BaoHiemXaHoi"]);
                giamtru.BaoHiemYTe = Convert.ToDouble(row["BaoHiemYTe"]);
                giamtru.BaoHiemThatNghiep = Convert.ToDouble(row["BaoHiemThatNghiep"]);                
                giamtru.TongGiamTru = Convert.ToDouble(row["TongGiamTru"]);
                ds.Add(giamtru);
            }
            return ds;
        }
        public string TimMa(String ma)
        {
            data.TimMa(ma);
            if (data != null)
                return ma;
            return null;
        }

        public string TimTen(string ten)
        {
            data.TimTen(ten);
            if (data != null)
                return ten;
            return null;
        }

        public DataRow NewRow()
        {
            return data.NewRow();
        }
        public void Add(DataRow row)
        {
            data.Add(row);
        }
        public bool Save()
        {
            return data.Save();
        }
        public void Update()
        {
            bs.MoveNext();
            data.Save();
        }
    }
}
